package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-04-27 14:51
 */
public class QLint406 {
    public int minimumSize(int[] nums, int s) {
        if(nums == null || nums.length == 0) {
            return -1;
        }

        int sum = 0;
        int i = 0;
        int res = Integer.MAX_VALUE;
        for (int j = 0; j < nums.length; j++) {
            sum += nums[j];

            while (sum >= s) {
                res = Math.min(res, j - i + 1);
                sum -= nums[i];
                i++;
            }
        }

        return res != Integer.MAX_VALUE ? res : -1;
    }
}
